package com.fly.push.flux.low.impl;

import org.springframework.stereotype.Service;

import com.fly.push.flux.low.SsePublisherService;

import reactor.core.publisher.DirectProcessor;
import reactor.core.publisher.Flux;

@Service
@SuppressWarnings("deprecation")
public class DirectProcessorSsePublisherService implements SsePublisherService
{
    DirectProcessor<String> processor = DirectProcessor.create();
    
    Flux<String> flux = processor.replay().autoConnect();
    
    @Override
    public Flux<String> getMessages()
    {
        return flux;
    }
    
    @Override
    public void publishMessage(String message)
    {
        processor.onNext(message);
    }
    
    @Override
    public void complete()
    {
        processor.onComplete();
    }
}